package com.sfac.day02.modules.test.controller;

import com.github.pagehelper.PageInfo;
import com.sfac.day02.modules.common.entity.ResultBean;
import com.sfac.day02.modules.common.entity.SearchBean;
import com.sfac.day02.modules.test.entity.City;
import com.sfac.day02.modules.test.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class CityController {
    @Autowired
    private CityService cityService;
    @PostMapping(value = "/city", consumes = "application/json")
    public ResultBean<City> addCity(@RequestBody City city) {
        return cityService.addCity(city);
    }
    @PutMapping(value = "/city", consumes = "application/x-www-form-urlencoded")
    public ResultBean<City> updateCity(@ModelAttribute City city) {
        return cityService.updateCity(city);
    }
    @DeleteMapping("/city/{cityId}")
    public ResultBean<City> deleteCityById(@PathVariable Integer cityId) {
        return cityService.deleteCityById(cityId);
    }
    @GetMapping("/city/{cityId}")
    public ResultBean<City> selectCityById(@PathVariable Integer cityId) {
        return cityService.selectCityByCityId(cityId);
    }
 /*   @GetMapping("/city/{cityId}")
    public ResultBean<City> getCityByCity(@PathVariable int cityId){
        return cityService.getCityByCityId(cityId);
    }*/

    /**
     * 127.0.0.1/api/cities ---- post
     * {"currentPage":1, "pageSize":5, "keyWord":"china", "orderBy":"ci.city_id", "direction":"desc"}
     */
    @PostMapping(value = "/cities",consumes = "application/json")
    public PageInfo<City> getgetCitiesBySearchBean(SearchBean searchBean){
        return cityService.getgetCitiesBySearchBean(searchBean);
    }


}
